/**
 * Copyright 2013-2015
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */	  

package com.cos.controller.app.appuser.circle;

import java.util.ArrayList;
import java.util.List;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletResponse;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.cos.controller.base.BaseController;
import com.cos.service.interfaces.circle.CompanyDynamicService;
import com.cos.util.AppUtil;
import com.cos.util.PageData;
import com.cos.util.ResponseUtil;

import net.sf.json.JSONArray;
import net.sf.json.JSONObject;

/**
 * 企业动态接口类
 * <p/>
 * 
 * @author <a href="mailto:978954852@qq.com">xfjin</a>
 * @version  Date: 2016年4月13日 下午2:25:37
 * @serial 1.0
 * @since 2016年4月13日 下午2:25:37
 */
@Controller
@RequestMapping("/appuser")
public class CompanyDynamic extends BaseController{
	
	@Resource
	private CompanyDynamicService companyDynamicService;
	
	
	/**
	 * 关注的企业列表
	 * @param response  用户ID
	 * @throws Exception
	 */
	@RequestMapping(value="/getFocusCompany")
	@ResponseBody
	public void getFocusCompany(HttpServletResponse response) throws Exception{
		logBefore(logger, "save comment");
		PageData pd = new PageData();
		JSONObject company = new JSONObject();
		pd = this.getPageData();
		String result = "00" ;
			try{	
				if(AppUtil.checkParam("getGroup", pd)){
				List<PageData> companyList = new ArrayList<PageData>();
				companyList = companyDynamicService.getFocusCompany(pd);
				JSONArray rows = JSONArray.fromObject(companyList);
				result="02" ; //发布评论成功
				company.put("rows", rows);
				}else{
					result = "03";//参数不合法
				}
			}catch(Exception e){
				e.printStackTrace();
				logger.error(e.toString()) ;
				result ="01" ; //发布评论失败
			}finally{
				company.put("result",result) ;
			}
			ResponseUtil.write(response, company);
	}
	
	
	/**
	 * 关注一个企业
	 * @param response
	 * @throws Exception
	 */
	@RequestMapping(value="/saveFocusCompany")
	@ResponseBody
	public void saveFocusCompany(HttpServletResponse response) throws Exception{
		logBefore(logger, "save comment");
		PageData pd = new PageData();
		JSONObject company = new JSONObject();
		pd = this.getPageData() ;
		String result = "00" ;
			try{	
				if(AppUtil.checkParam("getNoteCompany", pd)){
				pd.put("ID", this.get32UUID());
				companyDynamicService.saveFocusCompany(pd);
				result="02" ; //发布评论成功
				}else{
					result = "03";//参数不合法
				}
			}catch(Exception e){
				e.printStackTrace();
				logger.error(e.toString()) ;
			}finally{
				company.put("result",result) ;
			}
			ResponseUtil.write(response, company);
	}
	
	

	
	/**
	 * 获取收藏的动态列表
	 * @param response 
	 * @throws Exception
	 */
	@RequestMapping(value="/getCompanyCollection")
	@ResponseBody
	public void getCompanyCollection(HttpServletResponse response) throws Exception{
		logBefore(logger, "save comment");
		PageData pd = new PageData();
		JSONObject company = new JSONObject();
		pd = this.getPageData() ;
		String result = "00" ;
			try{	
				if(AppUtil.checkParam("getGroup", pd)){
					List<PageData> companyList = new ArrayList<PageData>();
					companyList = companyDynamicService.getCompanyCollection(pd); //获取推荐企业的列表
					JSONArray rows = JSONArray.fromObject(companyList);
					result="02" ; 
					company.put("rows", rows);
				}else{
					result = "03";//参数不合法
				}
			}catch(Exception e){
				e.printStackTrace();
				logger.error(e.toString()) ;
			}finally{
				company.put("result",result) ;
			}
			ResponseUtil.write(response, company);
	}
	
	/**
	 * 收藏企业的动态
	 * @param response
	 * @throws Exception
	 */
	@RequestMapping(value="/saveCompanyCollection")
	@ResponseBody
	public void saveCompanyCollection(HttpServletResponse response) throws Exception{
		logBefore(logger, "save comment");
		PageData pd = new PageData();
		JSONObject company = new JSONObject();
		pd = this.getPageData() ;
		String result = "00" ;
			try{	
				if(AppUtil.checkParam("saveCompanyCollection", pd)){
					pd.put("ID", this.get32UUID());
					companyDynamicService.saveCompanyCollection(pd);
					result="02" ; 
				}else{
					result = "03";//参数不合法
				}
			}catch(Exception e){
				e.printStackTrace();
				logger.error(e.toString()) ;
			}finally{
				company.put("result",result) ;
			}
			ResponseUtil.write(response, company);
	}
	
	
	/**
	 * 类别列表
	 * @param response
	 * @throws Exception
	 */
	@RequestMapping(value="/getCompanyType")
	@ResponseBody
	public void getCompanyType(HttpServletResponse response) throws Exception{
		logBefore(logger, "save comment");
		PageData pd = new PageData();
		JSONObject company = new JSONObject();
		pd = this.getPageData() ;
		String result = "00" ;
			try{	
				if(AppUtil.checkParam("getCompanyType", pd)){
					List<PageData> typeList = new ArrayList<PageData>();
					typeList = companyDynamicService.getCompanyType(pd);
					JSONArray rows = JSONArray.fromObject(typeList);
					result="02" ; 
					company.put("rows", rows);
				}else{
					result = "03";//参数不合法
				}
			}catch(Exception e){
				e.printStackTrace();
				logger.error(e.toString()) ;
			}finally{
				company.put("result",result) ;
			}
			ResponseUtil.write(response, company);
	}
	
	/**
	 * 根据类别获取企业列表，企业圈里面都全部浏览
	 * @param response  T_ID
	 * @throws Exception
	 */
	@RequestMapping(value="/getCompanyByType")
	@ResponseBody
	public void getCompanyByType(HttpServletResponse response) throws Exception{
		logBefore(logger, "save comment");
		PageData pd = new PageData();
		JSONObject company = new JSONObject();
		pd = this.getPageData() ;
		String result = "00" ;
			try{	
				if(AppUtil.checkParam("getCompanyType", pd)){
				List<PageData> companyList = new ArrayList<PageData>();
				companyList = companyDynamicService.getCompanyByType(pd);
				JSONArray rows = JSONArray.fromObject(companyList);
				result="02" ; //发布评论成功
				company.put("rows", rows);
				}else{
					result = "03";//参数不合法
				}
			}catch(Exception e){
				e.printStackTrace();
				logger.error(e.toString()) ;
				result ="01" ; //发布评论失败
			}finally{
				company.put("result",result) ;
			}
			ResponseUtil.write(response, company);
	}
	
	
	/**
	 * 我的定制企业列表
	 * @param response  U_ID ,T_ID
	 * @throws Exception
	 */
	@RequestMapping(value="/getCompanyCustom")
	@ResponseBody
	public void getCompanyCustom(HttpServletResponse response) throws Exception{
		logBefore(logger, "save comment");
		PageData pd = new PageData();
		JSONObject company = new JSONObject();
		pd = this.getPageData() ;
		String result = "00" ;
			try{	
				if(AppUtil.checkParam("getCompanyCustom", pd)){
				List<PageData> companyList = new ArrayList<PageData>();
				companyList = companyDynamicService.getCompanyCustom(pd);
				JSONArray rows = JSONArray.fromObject(companyList);
				result="02" ; //发布评论成功
				company.put("rows", rows);
				}else{
					result = "03";//参数不合法
				}
			}catch(Exception e){
				e.printStackTrace();
				logger.error(e.toString()) ;
				result ="01" ; //发布评论失败
			}finally{
				company.put("result",result) ;
			}
			ResponseUtil.write(response, company);
	}
	
	
	/**
	 * 我的定制增加一个企业
	 * @param response
	 * @throws Exception
	 */
	@RequestMapping(value="/saveCompanyCustom")
	@ResponseBody
	public void saveCompanyCustom(HttpServletResponse response) throws Exception{
		logBefore(logger, "save comment");
		PageData pd = new PageData();
		JSONObject company = new JSONObject();
		pd = this.getPageData() ;
		String result = "00" ;
			try{	
				if(AppUtil.checkParam("getNoteCompany", pd)){
					pd.put("ID", this.get32UUID());
					companyDynamicService.saveCompanyCustom(pd);
					result="02" ; //发布评论成功
				}else{
					result = "03";//参数不合法
				}
			}catch(Exception e){
				e.printStackTrace();
				logger.error(e.toString()) ;
			}finally{
				company.put("result",result) ;
			}
			ResponseUtil.write(response, company);
	}
	/**
	 * 浏览某个公司的动态
	 * @param response  C_ID
	 * @throws Exception
	 */
	/*@RequestMapping(value="/getCompanyDynamicByCID")
	@ResponseBody
	public void getCompanyDynamicByCID(HttpServletResponse response) throws Exception{
		logBefore(logger, "save comment");
		PageData pd = new PageData();
		JSONObject company = new JSONObject();
		pd = this.getPageData() ;
		String result = "00" ;
			try{	
				if(AppUtil.checkParam("getCompanyCustom", pd)){
				List<PageData> companyList = new ArrayList<PageData>();
				companyList = companyDynamicService.getCompanyCustom(pd);
				JSONArray rows = JSONArray.fromObject(companyList);
				result="02" ; //发布评论成功
				company.put("rows", rows);
				}else{
					result = "03";//参数不合法
				}
			}catch(Exception e){
				e.printStackTrace();
				logger.error(e.toString()) ;
				result ="01" ; //发布评论失败
			}finally{
				company.put("result",result) ;
			}
			ResponseUtil.write(response, company);
	}*/
	
}